package com.frank.oj.controller.file;

import com.frank.oj.common.result.CommonResult;
import com.frank.oj.service.file.UserFileService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.omg.CORBA.COMM_FAILURE;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author frank
 * @Date 2024/3/28
 */
@RestController
@RequestMapping("/api/file")
public class UserFileController {
    @Resource
    private UserFileService userFileService;

    @RequestMapping("/generate-user-excel")
    @RequiresAuthentication
    @RequiresRoles("root")
    public CommonResult<Void> generateUserExcel(@RequestParam("key") String key, HttpServletResponse response) {
        try {
            userFileService.generateUserExcel(key, response);
            return CommonResult.successResponse();
        } catch (Exception e) {
            return CommonResult.errorResponse("下载出错");
        }
    }

}
